<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<title>弹窗</title>
	<meta name ="description" content="弹窗">
	<style>
		.layui-form{
			padding-top:15px;
			padding-right: 15px;
		}
	</style>
</head>
<body>
<div class="layui-form">
	<div class="layui-form-item" style="display: none">
		<label class="layui-form-label">手机号</label>
		<div class="layui-input-inline">
			<input type="text" id="phone" name="phone" value="<?php if(isset($mobile)){echo $mobile;}?>" required  lay-verify="required" placeholder="请输入手机号" autocomplete="off" class="layui-input">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">验证码</label>
		<div class="layui-input-block"  >
			<input type="text" name="code" id="code" required lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input" style="width: 100px; display: inline-block;margin-right: 10px;">
			<button class="layui-btn able" id="getCode">获取验证码</button>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" style="float: left;" id="sub">提交</button>
		</div>

	</div>
</div>
<script>
	var phone = $("#phone").val();
	$(function(){
		$.getJSON("/activity/ajaxSendCode",{mobile:phone,activity_name:'jinrong',qd:qd},function(logJson) {
			if (logJson.status == 'ok') {
//				layer.msg("验证码发送成功");
			}else{
				layer.msg(logJson.status);
			}
		});
		$("#getCode").html("发送中..").removeClass('able')
		setTimeout(time,1000)
	});

	$(document).on("touchend",'#getCode.able',function(){
		if(phone == "" || undefined){
			layer.msg("请填写手机号");
			return false;
		}
		$.getJSON("/activity/ajaxSendCode",{mobile:phone,activity_name:'jinrong',qd:qd},function(logJson) {
			if (logJson.status == 'ok') {
//				layer.msg("验证码发送成功");
			}else{
				layer.msg(logJson.status);
			}
		});
		$(this).html("发送中..").removeClass('able')
		setTimeout(time,1000)
	})
	function time(){
		var time = 60
		var countDown = setInterval(fun,1000)
		function fun(){
			--time
			$('#getCode').html(time+'s后获取')
			if (time == 0) {
				clearInterval(countDown)
				$('#getCode').html('重新获取').addClass('able')
			}
		}
	}
	// 提交
	$("#sub").on("touchend",function(){
		var phone = $("#phone").val();
		var code = $("#code").val();
		// alert(nums);return false;
		var myreg = /^((\d{3}-\d{8}|\d{4}-\d{7,8})|(1[3|5|7|8][0-9]{9}))$/;
		if (phone=="") {
			layer.msg('手机号码不能为空');
			return false;
		}
		if(!myreg.test(phone)){
			layer.msg("手机号格式不正确");
			return false;
		}
		if (code=="") {
			layer.msg('请填写验证码');
			return false;
		}
		var URL="/activity/subTanChuang";
		$.ajax({
			type: "get",
			url: URL,
			dataType:'json',
			data: {
				'code':code,
				'phone':phone,
			},
			success: function(data){
//				console.log(data);return false;
				if(data.code == 200){
					layer.msg(data.msg, {
						time: 1000, //20s后自动关闭
					});
					window.location.href = "/Activity/jinrong?qd="+qd;
				}else{
					layer.msg(data.msg, {
						time: 1000, //20s后自动关闭
					});
				}


			}
		});
	});
</script>
</body>
</html>